package gui;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableRowSorter;

import util.MarketValueComparator;

public class MarketTable extends JTable {

  TableRowSorter<AbstractTableModel> _marketValueSorter;

  public MarketTable(TableRowSorter<AbstractTableModel> marketValueSorter) {
    super();
    _marketValueSorter = marketValueSorter;

    setRowSorter(_marketValueSorter);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  }

  public void activateSystemListModel(AbstractTableModel model) {
    setModel(model);
    setDefaultRenderer(Object.class, new DefaultTableCellRenderer());
    _marketValueSorter.setModel(model);
    _marketValueSorter.setComparator(1, new MarketValueComparator());
    _marketValueSorter.setComparator(2, new MarketValueComparator());
  }
}
